package com.lwy.qiuchao.field.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwy.qiuchao.field.dao.CityDao;
import com.lwy.qiuchao.field.dao.FieldDao;
import com.lwy.qiuchao.field.entity.CityEntity;
import com.lwy.qiuchao.field.entity.FieldInfoEntity;
import com.lwy.qiuchao.field.vo.FieldDetailInfoEntityVo;

import com.lwy.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lwy.qiuchao.field.entity.FieldEntity;
import com.lwy.qiuchao.field.service.FieldService;
import com.lwy.common.utils.PageUtils;


/**
 * 
 *
 * @author lwy
 * @email ${email}
 * @date 2020-12-01 14:41:42
 */
@RestController
@RequestMapping("field/field")
public class FieldController {
    @Autowired
    private FieldService fieldService;
    @Autowired
    FieldDao fieldDao;
    @Autowired
    CityDao cityDao;

    @PostMapping("/addField")
    public R addField(@RequestBody FieldEntity fieldEntity){
        fieldService.addField(fieldEntity);
        return R.ok();
    }


    @GetMapping("/{fieldId}")
    public String getDetailInfoEntity(@PathVariable("fieldId") Long fieldId){
        String fieldName = fieldService.getFieldName(fieldId);
        return fieldName;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fieldService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{fieldId}")
    public R info(@PathVariable("fieldId") Long fieldId){
		FieldEntity field = fieldService.getById(fieldId);

        return R.ok().put("field", field);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FieldEntity field){
		fieldService.save(field);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FieldEntity field){
		fieldService.updateById(field);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] fieldIds){
		fieldService.removeByIds(Arrays.asList(fieldIds));
        return R.ok();
    }

}
